#ifndef OPSTA
#define OPSTA

#include "VMPFocus.hpp"
#include "operations.hpp"

#include "op name.hpp"
#include "op var.hpp"
#include "op point.hpp"
#include "hlp blank.hpp"

//	Operation var:
//Formula:
//var:blank::newvar::blank:?(,:newvar::blank:?)*;

//preLining:
void funOpStaPreL(ListIdentity* what){
	for(int i=0; i<what->length(); ++i)
		(*what)[i]->Identifier=&TEXT_ELEMENT;
	ParserRename(what,"blank",TEXT_BLANK);
	ParserRename(what,".",TEXT_POINTTXT);
	ParserRename(what,"name",TEXT_NAME);
}

//PostLining:

//MkTree:
ptrParsedElement funOpStaMkTree(ptrText code, ptrIdentity identity, ptrParsedElement PE){
	ptrOperation opB=Operations[TEXT_BLANK];
	cList<bool>* x=new cList<bool>();
	for (int i=2; i<identity->SubIdentities->length();){
		if ((*(identity->SubIdentities))[i]->Operation==opB)
			++i;
		if ((*code)[(*(identity->SubIdentities))[i]->Range.begin-1]=='='){
			x->push(true);
			++i;
		}
		else
			x->push(false);
		if (i>=identity->SubIdentities->length())
			break;
		if ((*(identity->SubIdentities))[i]->Operation==opB)
			++i;
		++i;
	};

	PE->Extended=(void*)x;
	return PE;
};

//Evaluate:
sRecord funOpStaEva(ptrRETNode retnode, ptrParsedElement pe, void* extended){
	cList<bool>* hasValue=(cList<bool>*)(pe->Extended);
	for (int i=0; i<hasValue->length();++i){
		try{
			eval(retnode,pe->SubElements[i],0);
			throw ReDefining();
		}catch(Undefined& what){
			sRecord value=sRecord();
			if ((*hasValue)[i]){
				value=eval(retnode,pe->SubElements[i+1],0);
				++i;
			};
			if (what.which)
				what.which->Statics->push(*(what.name),value);
			else
				retnode->Dough->Statics->push(*(what.name),value);
		}
	};
	return NULL;
}


ptrOperation loadOpSta(){
	ptrOperation tmp=new cOperation();
	tmp->Name="static";
	tmp->onEvaluate=funOpStaEva;
	tmp->onPreLining=funOpStaPreL;
	tmp->onMakingTree=funOpStaMkTree;
	tmp->onPostLining=NULL;
	tmp->onFoundIdentity=NULL;//funOpXEFI;
	tmp->Formula="static:blank:(:point:|:name:)(:blank:?=:blank:?(:element:|:point:|:name:))?";  //not completede.
	return tmp;
}


#endif